/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MENU_LOGIN.java
 *
 * Created on Sep 25, 2010, 11:11:57 PM
 */

package Java;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.*;


/**
 *
 * @author akmal
 */
public class MENU_LOGIN extends javax.swing.JFrame {



    private String url = "jdbc:oracle:thin:@localhost:1521:XE";
    private String userID = "HR";
    private String userPW = "hr";
    private Connection con;
    private Statement stmt;
    private ResultSet rset;



    String TableNumber = "1";
    String Menucode = "1001";
    /** Creates new form MENU_LOGIN */
    public MENU_LOGIN() {
        super("LOGIN");
        initComponents();
        this.setLocationRelativeTo(null);
        MenuCode.setFocusable(false);
        MenuCode.setText(Menucode);
        Okbutton.setEnabled(false);
        
    }
/*
    MENU_LOGIN(String a,String b)
    {
        super("LOGIN");
        initComponents();
        this.setLocationRelativeTo(null);
        TableNumber = a;
        Menucode = b;
        MenuCode.setText(b);
        MenuCode.setFocusable(false);
    }
*/
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        Okbutton = new javax.swing.JButton();
        BackButton = new javax.swing.JButton();
        OrderButton = new javax.swing.JButton();
        ReserveButton = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        TableSelect = new javax.swing.JComboBox();
        MenuCode = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Okbutton.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13)); // NOI18N
        Okbutton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        Okbutton.setText("NEXT");
        Okbutton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        Okbutton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OkbuttonActionPerformed(evt);
            }
        });
        Okbutton.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                OkbuttonKeyPressed(evt);
            }
        });
        Okbutton.setBounds(330, 340, 70, 30);
        jLayeredPane1.add(Okbutton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BackButton.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13));
        BackButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        BackButton.setText("BACK");
        BackButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackButtonActionPerformed(evt);
            }
        });
        BackButton.setBounds(410, 340, 70, 30);
        jLayeredPane1.add(BackButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        OrderButton.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13)); // NOI18N
        OrderButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        OrderButton.setText("ORDER !");
        OrderButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        OrderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OrderButtonActionPerformed(evt);
            }
        });
        OrderButton.setBounds(290, 150, 160, 40);
        jLayeredPane1.add(OrderButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ReserveButton.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13)); // NOI18N
        ReserveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        ReserveButton.setText("MAKE RESERVATION");
        ReserveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        ReserveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReserveButtonActionPerformed(evt);
            }
        });
        ReserveButton.setBounds(290, 210, 160, 40);
        jLayeredPane1.add(ReserveButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cancel.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13)); // NOI18N
        cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        cancel.setText("CANCEL");
        cancel.setEnabled(false);
        cancel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        cancel.setBounds(60, 260, 100, 30);
        jLayeredPane1.add(cancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TableSelect.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13)); // NOI18N
        TableSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Table 1", "Table 2", "Table 3", "Table 4", "Table 5", "Table 6", "Table 7", "Table 8", "Table 9", "Table 10" }));
        TableSelect.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Table Number", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("DejaVu Serif Condensed", 1, 13))); // NOI18N
        TableSelect.setEnabled(false);
        TableSelect.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                TableSelectPropertyChange(evt);
            }
        });
        TableSelect.setBounds(40, 120, 160, 50);
        jLayeredPane1.add(TableSelect, javax.swing.JLayeredPane.DEFAULT_LAYER);

        MenuCode.setBackground(new java.awt.Color(204, 255, 255));
        MenuCode.setFont(new java.awt.Font("DejaVu Serif Condensed", 0, 13));
        MenuCode.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Menu Code", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.ABOVE_TOP, new java.awt.Font("DejaVu Serif Condensed", 1, 14))); // NOI18N
        MenuCode.setEnabled(false);
        MenuCode.setBounds(40, 190, 160, 50);
        jLayeredPane1.add(MenuCode, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(0, 80, 500, 30);
        jLayeredPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator2.setBounds(0, 330, 500, 20);
        jLayeredPane1.add(jSeparator2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Option", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Serif Condensed", 3, 15))); // NOI18N
        jLabel3.setBounds(260, 110, 220, 190);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 24));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("MENU BROWSING");
        jLabel2.setBounds(120, 20, 250, 60);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/abstract_0072.jpg"))); // NOI18N
        jLabel1.setBounds(-120, -60, 1010, 540);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackButtonActionPerformed

        this.setVisible(false);
        new FIRST_SCREEN().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_BackButtonActionPerformed

    private void OkbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OkbuttonActionPerformed
        this.setVisible(false);
        try {
            new MENU_SELECTION_MAIN(Menucode, TableNumber).setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(MENU_LOGIN.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_OkbuttonActionPerformed

    private void OkbuttonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_OkbuttonKeyPressed
      // TODO add your handling code here:
    }//GEN-LAST:event_OkbuttonKeyPressed

    private void TableSelectPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_TableSelectPropertyChange
    
    TableSelect.addItemListener(new ItemListener()
    {
        public void itemStateChanged(ItemEvent e)
        {

          if (TableSelect.getSelectedIndex() == 0)
            {
                TableNumber = "1";
                Menucode = "1001";
                MenuCode.setText(Menucode);
               
            }
          else if ( TableSelect.getSelectedIndex()== 1)
            {
                TableNumber = "2";
                Menucode = "1002";
                MenuCode.setText(Menucode);
               
            }
          else if (TableSelect.getSelectedIndex() == 2)
            {
                TableNumber = "3";
                Menucode = "1003";
                MenuCode.setText(Menucode);
                
            }
          else if (TableSelect.getSelectedIndex() == 3)
            {
                TableNumber = "4";
                Menucode = "1004";
                MenuCode.setText(Menucode);
              
            }
          else if (TableSelect.getSelectedIndex() == 4)
            {
                TableNumber = "5";
                Menucode = "1005";
                MenuCode.setText(Menucode);
               
            }
          else if (TableSelect.getSelectedIndex() == 5)
            {
                TableNumber = "6";
                Menucode = "1006";
                MenuCode.setText(Menucode);
                
            }
          else if (TableSelect.getSelectedIndex() == 6)
            {
                TableNumber = "7";
                Menucode = "1007";
                MenuCode.setText(Menucode);
            }
          else if (TableSelect.getSelectedIndex() == 7)
            {
                TableNumber = "8";
                Menucode = "1008";
                MenuCode.setText(Menucode);
                
            }
          else if (TableSelect.getSelectedIndex() == 8)
            {
                TableNumber = "9";
                Menucode = "1009";
                MenuCode.setText(Menucode);
               
            }
          else if (TableSelect.getSelectedIndex() == 9)
            {
                TableNumber = "10";
                Menucode = "1010";
                MenuCode.setText(Menucode);
             
            }
          }
     });           
    }//GEN-LAST:event_TableSelectPropertyChange


    //***************************** DATEBASE CONNECTION PART ******************************
    private void connectDatabase()
    {
        try
        {
            Class.forName("oracle.jdbc.OracleDriver");
            con=DriverManager.getConnection(url, userID, userPW);
        }

        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(EMPLOYEE_PROFILE.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(EMPLOYEE_PROFILE.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    private void OrderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OrderButtonActionPerformed
         TableSelect.setEnabled(true);
         MenuCode.setEnabled(true);
         cancel.setEnabled(true);
         Okbutton.setEnabled(true);
         ReserveButton.setEnabled(false);
    }//GEN-LAST:event_OrderButtonActionPerformed

    
    private void ReserveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReserveButtonActionPerformed
        this.setVisible(false);
        new CUS_RESERVATION().setVisible(true);  
    }//GEN-LAST:event_ReserveButtonActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed

        TableSelect.setEnabled(false);
        MenuCode.setEnabled(false);
        ReserveButton.setEnabled(true);
        cancel.setEnabled(false);
        Okbutton.setEnabled(false);
    }//GEN-LAST:event_cancelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MENU_LOGIN().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BackButton;
    private javax.swing.JTextField MenuCode;
    private javax.swing.JButton Okbutton;
    private javax.swing.JButton OrderButton;
    private javax.swing.JButton ReserveButton;
    private javax.swing.JComboBox TableSelect;
    private javax.swing.JButton cancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables

}
